using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Input.Touch;


namespace GameForKids
{

    public class PauseScreen : DrawableGameComponent
    {

        public event EventHandler Clicked = delegate { };
        // hinh nen
        protected Texture2D blackBackground;
        protected Texture2D background;
        protected Vector2 posOfBack;
        // cac button
        protected Button replayButton;
        protected Button resumeButton;
        protected Button menuButton;
        // tieu de
        protected Texture2D title;
        // am thanh
        protected SoundEffect clicksound;

        public bool show { get; set; }

        public void showPause()
        {
            show = true;
        }

        public void hidePause()
        {
            show = false;
        }

        public PauseScreen(Game game): base(game)
        {
            blackBackground = this.Game.Content.Load<Texture2D>("MainMenu/Images/black_background");
            background = this.Game.Content.Load<Texture2D>("Pause/background");
            posOfBack = new Vector2((GameForKids.WIDTH-background.Width)/2,(GameForKids.HEIGHT-background.Height)/2);
           
            if (GameForKids.language == GameForKids.ANH)
                title = this.Game.Content.Load<Texture2D>("Pause/pause");
            else
                title = this.Game.Content.Load<Texture2D>("Pause/tamdung");

            replayButton = new Button(this.Game.Content.Load<Texture2D>("Pause/replayButton"), 
                this.Game.Content.Load<Texture2D>("Pause/replayButtonPress"),
                this.Game.Content.Load<Texture2D>("Pause/replayButtonPress"));
            replayButton.Location = new Point((int)posOfBack.X + 45, (int)posOfBack.Y + 70);
            replayButton.Clicked += replayButton_Clicked;

            resumeButton = new Button(this.Game.Content.Load<Texture2D>("Pause/resumeButton"),
                this.Game.Content.Load<Texture2D>("Pause/resumeButtonPress"),
                this.Game.Content.Load<Texture2D>("Pause/resumeButtonPress"));
            resumeButton.Location = new Point((int)posOfBack.X + 135, (int)posOfBack.Y + 40);
            resumeButton.Clicked += resumeButton_Clicked;

            menuButton = new Button(this.Game.Content.Load<Texture2D>("Pause/menuButton"),
                this.Game.Content.Load<Texture2D>("Pause/menuButtonPress"),
                this.Game.Content.Load<Texture2D>("Pause/menuButtonPress"));
            menuButton.Location = new Point((int)posOfBack.X + 230, (int)posOfBack.Y + 80);
            menuButton.Clicked += menuButton_Clicked;

            clicksound = this.Game.Content.Load<SoundEffect>("Login/Sounds/button_click");
        }

        void menuButton_Clicked(object sender, EventArgs e)
        {
            if (GameForKids.ISMUSIC)
                clicksound.Play();
            PauseClickState.clickstate = PauseClickState.ClickState.menu;
        }

        void resumeButton_Clicked(object sender, EventArgs e)
        {
            if (GameForKids.ISMUSIC)
                clicksound.Play();
            PauseClickState.clickstate = PauseClickState.ClickState.resume;
        }

        void replayButton_Clicked(object sender, EventArgs e)
        {
            if (GameForKids.ISMUSIC)
                clicksound.Play();
            PauseClickState.clickstate = PauseClickState.ClickState.replay;
        }

        public virtual void Draw(SpriteBatch spriteBatch)
        {
            if (show)
            {
                spriteBatch.Draw(blackBackground, new Rectangle(0, 0, GameForKids.WIDTH, GameForKids.HEIGHT), new Color(255, 255, 255, 120));
                
                spriteBatch.Draw(background, new Rectangle(
                    (int)posOfBack.X, (int)posOfBack.Y, background.Width, background.Height), Color.White);
                
                spriteBatch.Draw(title,
                    new Rectangle((int)posOfBack.X + ((background.Width - title.Width) / 2),(int) posOfBack.Y - 27, title.Width, title.Height),
                    Color.White);
               
                resumeButton.Draw(spriteBatch);
                replayButton.Draw(spriteBatch);
                menuButton.Draw(spriteBatch);
            }
        }

        public void TouchEvent(TouchLocation touch)
        {
            resumeButton.TouchEvent(touch);
            replayButton.TouchEvent(touch);
            menuButton.TouchEvent(touch);
        }
    }
}
